package cn.bugstack.test;

import cn.bugstack.domain.strategy.model.entity.RaffleAwardEntity;
import cn.bugstack.domain.strategy.model.entity.RaffleFactorEntity;
import cn.bugstack.domain.strategy.service.IRaffleStrategy;
import cn.bugstack.domain.strategy.service.armory.IStrategyArmory;
import cn.bugstack.domain.strategy.service.armory.IStrategyDispatch;
import cn.bugstack.domain.strategy.service.rule.impl.RuleWeightLogicFilter;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.ReflectionTestUtils;

import javax.annotation.Resource;

@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
//@MapperScan("cn.bugstack.infrastructure.dao")
public class StrategyArmoryTest {
	@Resource
	private IRaffleStrategy raffleStrategy;

	@Resource
	private RuleWeightLogicFilter ruleWeightLogicFilter;

	@Before
	public void setUp() {
		ReflectionTestUtils.setField(ruleWeightLogicFilter, "userScore", 40500L);
	}

	@Test
	public void test_performRaffle() {
		RaffleFactorEntity raffleFactorEntity = RaffleFactorEntity.builder()
				.userId("xiaofuge")
				.strategyId(100001L)
				.build();

		RaffleAwardEntity raffleAwardEntity = raffleStrategy.performRaffle(raffleFactorEntity);

		log.info("请求参数：{}", JSON.toJSONString(raffleFactorEntity));
		log.info("测试结果：{}", JSON.toJSONString(raffleAwardEntity));
	}

	@Test
	public void test_performRaffle_blacklist() {
		RaffleFactorEntity raffleFactorEntity = RaffleFactorEntity.builder()
				.userId("user003")  // 黑名单用户 user001,user002,user003
				.strategyId(100001L)
				.build();

		RaffleAwardEntity raffleAwardEntity = raffleStrategy.performRaffle(raffleFactorEntity);

		log.info("请求参数：{}", JSON.toJSONString(raffleFactorEntity));
		log.info("测试结果：{}", JSON.toJSONString(raffleAwardEntity));
	}
}
